package com.lry.basic.juc;

import java.lang.ref.WeakReference;

public class TestWeakRef {

//    public static void main(String[] args) {
//        String s = "sd";
//        WeakReference weakReference = new WeakReference(s);
//        System.out.println(weakReference.get());
//        System.gc();//没清掉
//        System.out.println(weakReference.get());
//    }

//        public static void main(String[] args) {
//        String s = new String("ds");
//        WeakReference weakReference = new WeakReference(s);
//        System.out.println(weakReference.get());
//        System.gc();//没清掉
//        System.out.println(weakReference.get());
//    }

public static void main(String[] args) {

    WeakReference weakReference = new WeakReference("dsa");
    System.out.println(weakReference.get());
    System.gc();//没清掉
    System.out.println(weakReference.get());
}

//    public static void main(String[] args) {
//
//        WeakReference weakReference = new WeakReference(new String("dsa"));
//        System.out.println(weakReference.get());
//        System.gc();//清掉了
//        System.out.println(weakReference.get());
//    }

}
